/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var reverseList = function(head) {
  let res = null
  let temp = head
  while(temp) {
    let next = temp.next
    temp = res
    res = temp
    temp = next
  }
  return res
};